<< define "role/index.html" >>
<!DOCTYPE html>
<html lang="en" class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <link rel="stylesheet" href="/static/css/mbgadmin.css">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/mbgadmin.js"></script>
</head>
<body>
<div class="layui-card-body">
    <form class="layui-form" action="">
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <input class="layui-input" placeholder="角色名" name="name">
        </div>
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                <i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
    </form>
    <hr>
    <button class="layui-btn" onclick="xadmin.open('添加角色','/roles/create')" id="create">
        <i class="layui-icon"></i>添加角色
    </button>
    <table id="role" lay-filter="role"></table>
</div>
<script type="text/html" id="toolEvent">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table', 'form','layer'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;

        //初始化表格
        table.render({
            elem: '#role',
            id:"role",
            url: '/roles/lists',
            page: true,
            cols: [[
                {field: 'ID', title: 'ID'},
                {field: 'Name', title: '角色名称'},
                {field: 'describe', title: '角色描述'},
                {
                    field: 'creatorID', title: '创建者', templet: function (d) {
                        return d.creatorID.name
                    }
                },
                {
                    field: 'modifierID', title: '更新者', templet: function (d) {
                        return d.creatorID.name
                    }
                },
                {
                    field: 'isUsable', title: '状态', templet: function (d) {
                        return GoStatusFormatHTML(d.isUsable)
                    }
                },
                {
                    field: 'CreatedAt', title: '添加时间', templet(d) {
                        return GoTimeFormat(new Date(d.CreatedAt))
                    }
                },
                {
                    field: 'UpdatedAt', title: '修改时间', templet: function (d) {
                        return GoTimeFormat(new Date(d.UpdatedAt))
                    }
                },
                {field: 'experience', title: '操作', toolbar: '#toolEvent', width: 150},
            ]],
        });

        //监听表格事件
        table.on('tool(role)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    layer.close(index);
                    $.get("/roles/del/" + data.ID, {}, function (result) {
                        if (result.code === 0) {
                            layer.msg(result.msg);
                            obj.del();
                            table.reload('role', {});
                        }else {
                            layer.msg(result.msg)
                        }
                    });
                });
            } else if (layEvent === 'edit') {
                layer.open({
                    id:'edit_roles',
                    type:2,
                    title:"编辑角色",
                    skin: 'layui-layer-molv',
                    closeBtn:2,
                    anim:5,
                    area: ['680px', '520px'],
                    maxmin: false, //开启最大化最小化按钮
                    content:"/roles/edit",
                    success:function (layero,index){
                        // 获取子页面的iframe
                        var iframe = window['layui-layer-iframe'+index];
                        // 向子页面的全局函数child传参
                        iframe.child(data);
                    },
                })
            }
        });

        //搜索
        form.on('submit(sreach)', function (data) {
            table.reload('role', {
                where: data.field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });
    })
</script>

</body>
</html>
<< end >>